<?php
class BaseController
{
	protected $post = array();
	protected $get = array();
	protected $uId = 0;
	protected $userInfo = array();	//当前用户信息
	protected $config = array();
	
	public function __construct()
	{
		if( !get_magic_quotes_gpc() )
		{
			Common::prepareGPCData( $_GET );
			Common::prepareGPCData( $_POST );
		}

		$this->post = & $_POST;
		$this->get = & $_GET;
		$this->config = & Common::getConfig();
	}
	
	/**
	 * 设置当前用户ID
	 *
	 * @param int $userId
	 */
	public function setUserId( $uId )
	{
		$this->uId = $uId;
	}
	
	/**
	 *
	 * 外部变量的验证与过滤
	 * @todo delete?
	 * @param mixed $varName
	 * @param boolean $require
	 * @param boolean $isGet
	 */
	public function getParamInt( $varName , $require = true , $isGet = false )
	{
            
                
		$return = null;
		if( $isGet )
		{
			$method = '[get]';
			$return = empty( $this->get[$varName] ) ? null : (int)$this->get[$varName];
		}
		else
		{
			$method = '[post]';    
			$return = empty( $this->post[$varName] ) ? null : (int)$this->post[$varName];
                       
		}
		if( $require && is_null( $return ) )
		{
			throw new AppException( 10 , $method.':[' .$varName.']' );
		}
		if( $return < 0 )
		{
           
			throw new AppException( 10 , $method.':[' .$varName.']' );
		}
		return $return;
	}
        /**
	 *
	 * 外部变量的验证与过滤
	 * @todo delete?
	 * @param mixed $varName
	 * @param boolean $require
	 * @param boolean $isGet
	 */
	public function getParamIntArray( $varName , $require = true , $isGet = false )
	{
            
                
		$return = null;
		if( $isGet )
		{
			$method = '[get]';
			$return = empty( $this->get[$varName] ) ? null : $this->get[$varName];
		}
		else
		{
			$method = '[post]';    
			$return = empty( $this->post[$varName] ) ? null : $this->post[$varName];
                       
		}
		if( $require && is_null( $return ) )
		{
			throw new AppException( 10 , $method.':[' .$varName.']' );
		}
		if( $return < 0 )
		{
           
			throw new AppException( 10 , $method.':[' .$varName.']' );
		}
		return $return;
	}
        
	
	/**
	 *
	 * 外部变量的验证与过滤
	 * @todo delete?
	 * @param mixed $varName
	 * @param boolean $require
	 * @param boolean $isPost
	 * @throws WeiyouxiException
	 */
	public function getParamString( $varName , $require = true , $isPost = true )
	{       
		$return = null;
		if( $isPost )
		{    
                   
			$method = '[post]';
			$return = empty( $_POST[$varName] ) ? null : $this->post[$varName];
                  
		}
		else
		{   
			$method = '[get]';
			$return = empty( $this->get[$varName] ) ? null : $this->get[$varName];
		}
                
		if( $require && is_null( $return ) )
		{
                
                    throw new AppException( 10 , $method.':[' . $varName.']' );
		}
		return ($return) ;
	}
        
}